﻿using System.Xml;

namespace game1_2022_9_28_
{
    internal class Program
    {
        enum Directions
        {
            up,down,left,right
        }
        //记测试次数为5次
        const int count = 5;
        static void Main(string[] args)
        {           
            //定义反应时间time和错误次数error
            double time = 0;
            int error= 0;      
            //随即生成枚举中的方向
            Random rnd = new Random();           
            for(int i = 1; i<=count; i++)
            {              
                //清屏
                Console.Clear();
                Console.WriteLine($"第{i}次试验");
                //记录开始时间
                DateTime start = DateTime.Now;  
                //随机输出枚举中的项
                Directions directions = (Directions)rnd.Next(4);               
                Console.WriteLine(directions.ToString());
                bool flag = false;
                do
                {
                    //玩家输入答案
                    var input = Console.ReadKey().Key;
                    //验证
                    switch(directions)
                    {
                        case Directions.up:
                            if (input==ConsoleKey.UpArrow)
                            {
                                flag = true;
                            }
                            else
                            { 
                                flag = true; 
                                error++;                              
                            }
                            break;
                        case Directions.down:
                            if (input == ConsoleKey.DownArrow)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = true;
                                error++;                            
                            }
                            break ;
                        case Directions.left:
                            if (input == ConsoleKey.LeftArrow)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = true;
                                error++;                              
                            }
                            break;  
                        case Directions.right:
                            if (input == ConsoleKey.RightArrow)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = true;
                                error++;                         
                            }
                            break;  
                    }
                }while(flag==false);
                 //获取结束的时间
                    DateTime end = DateTime.Now;
                    //计算用时
                    time += (end - start).TotalSeconds;
            }
            Console.WriteLine($"至此耗时{time}秒，共出错{error}次");
        }
    }
}